{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "580ae31a-cfd0-4773-b785-820bbe50bf29",
   "metadata": {},
   "outputs": [],
   "source": [
    "import \"fmt\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "aed7b3f6-d1ae-4700-9994-546bb3d712af",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "6 <nil>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "fmt.Println(\"hello\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "4b93fb82-41d9-4a42-8d1f-44cb9303a22a",
   "metadata": {},
   "outputs": [],
   "source": [
    "package main\n",
    "\n",
    "import (\n",
    "\t\"fmt\"\n",
    ")\n",
    "\n",
    "func main() {\n",
    "\tvar (\n",
    "\t\ta []int\n",
    "\t\tb = []int{}\n",
    "\t\tc = []int{1, 2, 3}\n",
    "\t\td = c[:2]\n",
    "\t\te = c[0:2:cap(c)]\n",
    "\t\tf = c[:0]\n",
    "\t\tg = make([]int, 3)\n",
    "\t\th = make([]int, 2, 3)\n",
    "\t\ti = make([]int, 0, 3)\n",
    "\t)\n",
    "\tfmt.Printf(\"a\\t%#v\\nb\\t%#v\\nc\\t%#v\\nd\\t%#v\\ne\\t%#v\\nf\\t%#v\\ng\\t%#v\\nh\\t%#v\\ni\\t%#v\\n\", a, b, c, d, e, f, g, h, i)\n",
    "\n",
    "\tprintln(cap(h), cap(i))\n",
    "\n",
    "\ta = append(a, 1)\n",
    "\tfmt.Printf(\"%p\\n\", a)\n",
    "\ta = append(a, 1, 2, 3)\n",
    "\tfmt.Printf(\"%p\\n\", a)\n",
    "\ta = append(a, []int{1, 2, 3}...)\n",
    "\tfmt.Printf(\"%p\\n\", a)\n",
    "\tfmt.Printf(\"%#v\\n\", a)\n",
    "\n",
    "\ta = append([]int{0}, a...)\n",
    "\tfmt.Printf(\"%p\\n\", a)\n",
    "\ta = append([]int{-3, -2, -1}, a...)\n",
    "\tfmt.Printf(\"%p\\n\", a)\n",
    "\tfmt.Printf(\"%#v\\n\", a)\n",
    "}\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "982fd7ff-9c19-4bbb-87c8-2423823dff91",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a\t[]int(nil)\n",
      "b\t[]int{}\n",
      "c\t[]int{1, 2, 3}\n",
      "d\t[]int{1, 2}\n",
      "e\t[]int{1, 2}\n",
      "f\t[]int{}\n",
      "g\t[]int{0, 0, 0}\n",
      "h\t[]int{0, 0}\n",
      "i\t[]int{}\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "3 3\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0xc000041a50\n",
      "0xc000308360\n",
      "0xc00003d040\n",
      "[]int{1, 1, 2, 3, 1, 2, 3}\n",
      "0xc00003d080\n",
      "0xc000166840\n",
      "[]int{-3, -2, -1, 0, 1, 1, 2, 3, 1, 2, 3}\n"
     ]
    }
   ],
   "source": [
    "main()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "d32f1b7e-13f4-494d-b248-12e8a437dc0e",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "3 3\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a\t[]int(nil)\n",
      "b\t[]int{}\n",
      "c\t[]int{1, 2, 3}\n",
      "d\t[]int{1, 2}\n",
      "e\t[]int{1, 2}\n",
      "f\t[]int{}\n",
      "g\t[]int{0, 0, 0}\n",
      "h\t[]int{0, 0}\n",
      "i\t[]int{}\n",
      "0xc0003d4e88\n",
      "0xc0005a2220\n",
      "0xc000314940\n",
      "[]int{1, 1, 2, 3, 1, 2, 3}\n",
      "0xc000314980\n",
      "0xc00004a6c0\n",
      "[]int{-3, -2, -1, 0, 1, 1, 2, 3, 1, 2, 3}\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "42 <nil>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "var (\n",
    "    a []int\n",
    "    b = []int{}\n",
    "    c = []int{1, 2, 3}\n",
    "    d = c[:2]\n",
    "    e = c[0:2:cap(c)]\n",
    "    f = c[:0]\n",
    "    g = make([]int, 3)\n",
    "    h = make([]int, 2, 3)\n",
    "    i = make([]int, 0, 3)\n",
    ")\n",
    "fmt.Printf(\"a\\t%#v\\nb\\t%#v\\nc\\t%#v\\nd\\t%#v\\ne\\t%#v\\nf\\t%#v\\ng\\t%#v\\nh\\t%#v\\ni\\t%#v\\n\", a, b, c, d, e, f, g, h, i)\n",
    "\n",
    "println(cap(h), cap(i))\n",
    "\n",
    "a = append(a, 1)\n",
    "fmt.Printf(\"%p\\n\", a)\n",
    "a = append(a, 1, 2, 3)\n",
    "fmt.Printf(\"%p\\n\", a)\n",
    "a = append(a, []int{1, 2, 3}...)\n",
    "fmt.Printf(\"%p\\n\", a)\n",
    "fmt.Printf(\"%#v\\n\", a)\n",
    "\n",
    "a = append([]int{0}, a...)\n",
    "fmt.Printf(\"%p\\n\", a)\n",
    "a = append([]int{-3, -2, -1}, a...)\n",
    "fmt.Printf(\"%p\\n\", a)\n",
    "fmt.Printf(\"%#v\\n\", a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "585d0b6f-54ee-4cda-b3dd-604ecfc5fefb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[-3 -2 -1 0 1 1 2 3 1 2 3]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "08c735dd-a536-4998-8120-2e5f10d59669",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "12"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cap(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "fe6ad416-0820-4ae4-a91a-3a1696f0c2d6",
   "metadata": {},
   "outputs": [],
   "source": [
    "a = append(a, 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "ad141bc0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[-3 -2 -1 0 1 1 2 3 1 2 3 0]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "3e0ac6a5",
   "metadata": {},
   "outputs": [
    {
     "ename": "ERROR",
     "evalue": "cannot convert untyped constant {int 1} to <[]int>",
     "output_type": "error",
     "traceback": [
      "cannot convert untyped constant {int 1} to <[]int>"
     ]
    }
   ],
   "source": [
    "copy(a[i+1:], a[i:])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "ccb2d24b",
   "metadata": {},
   "outputs": [],
   "source": [
    "a = []int{1,2,3}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "d56b91b4",
   "metadata": {},
   "outputs": [],
   "source": [
    "a = a[:len(a)-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "f112dabd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1 2]"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "6ab77341",
   "metadata": {},
   "outputs": [],
   "source": [
    "a = a[:len(a)-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "53d5ab36",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1]"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "12bcb49a",
   "metadata": {},
   "outputs": [],
   "source": [
    "a = []int{1,2,3}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "9ce9b135",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1 2 3]"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "577d5c2e",
   "metadata": {},
   "outputs": [],
   "source": [
    "a = a[1:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "bdb35e01",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[2 3]"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "33f96242",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Go",
   "language": "go",
   "name": "gophernotes"
  },
  "language_info": {
   "codemirror_mode": "",
   "file_extension": ".go",
   "mimetype": "",
   "name": "go",
   "nbconvert_exporter": "",
   "pygments_lexer": "",
   "version": "go1.20.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
